package bintree.leetcode;

//606. 根据二叉树创建字符串

public class Num606_tree2str {
    private StringBuilder sb = new StringBuilder();
    public String tree2str(TreeNode root) {
        sb.append(root.val);

        if(root.left != null){
            sb.append("(");
            tree2str(root.left);
            sb.append(")");
        }else {
            if(root.right != null){
                sb.append("()");
            }
        }
        if(root.right != null){
            sb.append("(");
            tree2str(root.right);
            sb.append(")");
        }
        return sb.toString();
    }
}
